/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.zjdt.epserver.db.service4mysql;

import com.zjdt.epserver.db.dao.SiterDao;
import com.zjdt.epserver.db.dao.TripDao;
import com.zjdt.epserver.model.MyConstant;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;

/**
 *
 * @author dusin
 */
public class SiterServiceImpl {
    static Logger logger = Logger.getLogger(SiterServiceImpl.class);
    SiterDao siterDao;
    TripDao tripDao;

    public SiterServiceImpl(SiterDao siterDao,TripDao tripDao) {
        this.siterDao = siterDao;
        this.tripDao = tripDao;
    }    
    
    public List<Map<String,Object>> findAll(){
        return siterDao.findAll();
    }
    public Map<String,Object> findByName(String name){
        return siterDao.findByName(name);
    }
    
     public Map<String,Object> findByUsername(String username){
        return siterDao.findByUsername(username);
    }
    public Map<String,Object> login(String username,String password){
        return siterDao.login(username, password);
    }
    
    public boolean create(String username,String name,String phoneMobile,String note){
        return siterDao.doCreate(new Object[]{username,"888888",name,phoneMobile,note}); //默认密码888888
    }
    
    public boolean update(int id,String username,String name,String phoneMobile,String note){
        return siterDao.doUpdateById(new Object[]{username,name,phoneMobile,note,id});
    }
    
    public boolean remove(int id){
        return siterDao.doDeleteById(id);
    }
    
    public boolean changePassword(int id,String newPassword){
        return siterDao.doUpdatePassword(id, newPassword);
    }
    
    public boolean changePasswordByUsername(String username,String newPassword){
        return siterDao.doUpdatePasswordByUsername(username, newPassword);
    }
    
    public boolean changePassword(int id,String username,String oldPassword,String newPassword){
        Map<String,Object> result = siterDao.login(username, oldPassword);
        if(result!=null){
            return siterDao.doUpdatePassword(id, newPassword);
        }
        return false;
    }
    
    public boolean setFactory(int id,String fcode1,String fcode2,String fcode3,String fcode4){
        return siterDao.doUpdateFactory(id,fcode1,fcode2,fcode3,fcode4);
    }
    public boolean setTripDone(String rid){
        return tripDao.setStatus(rid, MyConstant.FINISHED);
    }
}
